package com.springboot.swagger2.web;

import com.springboot.swagger2.model.Order;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author liuwei
 * @version 2017/7/15 下午6:28
 * @modified TODO
 * @description 功能描述
 * @see
 * @since 1.0
 */
@RestController
@RequestMapping("/api/order")
public class OrderController {
    private Map<Long , Order> orderMap = new ConcurrentHashMap<Long, Order>();

    @ApiOperation(value = "订单列表" ,notes = "")
    @RequestMapping(value = "/getList" , method = RequestMethod.GET)
    public List<Order> getAll(){
        return new ArrayList<Order>(orderMap.values());
    }

    @ApiOperation(value = "下单" ,notes = "")
    @RequestMapping(value = "/save" , method = RequestMethod.POST)
    public String save(@ModelAttribute Order order){
        orderMap.put(order.getId(), order);
        return "success";
    }

    @ApiOperation(value = "订单查询" ,notes = "根据订单id查询订单")
    @ApiImplicitParam(name = "id" , required = true ,value = "订单id" , dataType = "Long")
    @RequestMapping(value = "/{id}" , method = RequestMethod.GET)
    public Order getById(@PathVariable Long id){
        return orderMap.get(id);
    }

}
